package com.amigo.online.provider.search.mapper;

import com.amigo.online.common.param.result.UserInfo;
import com.amigo.online.common.param.result.VideoInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @Author:LiangWu
 * @Date: 2019/6/13 18:35
 * @Description:
 */
@Mapper
public interface SearchMapper {

    @Select("SELECT * FROM user_tbl WHERE ( 1 = 1 ) AND nickname LIKE '%#{q}%' ORDER BY abs(length(nickname)- length('#{q}')) LIMIT #{start},#{rows} ")
    List<UserInfo> user(@Param("q") String q,@Param("start") Integer start,@Param("rows") Integer rows);

    @Select("select * from user_tbl where user_id = #{userId}")
    List<UserInfo> userId(@Param("userId") long userId);

    @Insert("insert into hotWord_tbl(word,create_time) values(#{word},#{time})")
    void insertHotWord(@Param("word") String word,@Param("time")Long time);

    @Select("select count(id) from hotWord_tbl where word = #{word}")
    Integer selectHotWord(@Param("word") String word);

    @Update("update hotWord_tbl set num = num + 1,update_time = #{time} where word = #{word}")
    void addNumHotWord(@Param("word")String word,@Param("time") Long time);

    @Select("SELECT * FROM video_tbl WHERE ( 1 = 1 ) AND title LIKE '%#{q}%' or content LIKE '%#{q}%' ORDER BY abs(length(title)- length('#{q}')) LIMIT #{start},#{rows}")
    List<VideoInfo> selectVideo(@Param("q") String q,@Param("start") Integer start,@Param("rows") Integer rows);
}
